<template>
	<main-content>
		<view class="content-color">
			<u-form :model="formData" ref="formDataRef" :rules='rules' label-width='auto'
				:label-style="{color: 'rgba(153, 153, 153, 1)' }">
				<view :class="{isDisabled:formType=='view'}" class="p-b-90">
					<template v-if="current === 0">
						<view class="p-16">
							<group-title>
						<template #icon>
							<view class="main-color">
								<u-icon name="title-icon" custom-prefix="custom-icon" />
							</view>
						</template>
						基本信息</group-title>
						</view>
						<view class="bg-white p-r-16 p-l-16">
							<template v-for="(item, index) in jIdentitiesList" :key="`${item?.userType}` - `${index}`">
								<template v-if="item?.userType == 0">
									<u-form-item label="超级管理员类型" :prop="`jIdentitiesList.${index}.idHolderType`"
										:required="rules[`jIdentitiesList.${index}.idHolderType`]?.[0].required">
										<my-select clearable input-align='right' v-model="item.idHolderType"
											:options="HOLDER_TYPE" />
									</u-form-item>
									<u-form-item label="超级管理员姓名" :prop="`jIdentitiesList.${index}.idDocName`"
										:required="rules[`jIdentitiesList.${index}.idDocName`]?.[0].required">
										<u-input input-align='right' v-model="item.idDocName" />
									</u-form-item>
									<u-form-item label="超级管理员证件类型" :prop="`jIdentitiesList.${index}.idDocType`"
										:required="rules[`jIdentitiesList.${index}.idDocType`]?.[0].required">
										<my-select clearable input-align='right' v-model="item.idDocType"
											:options="DOC_TYPE" />
									</u-form-item>
									<u-form-item label="超级管理员身份证件号码" :prop="`jIdentitiesList.${index}.idDocNumber`"
										:required="rules[`jIdentitiesList.${index}.idDocNumber`]?.[0].required">
										<u-input input-align='right' v-model="item.idDocNumber" />
									</u-form-item>
									<u-form-item label="证件正面照片" :prop="`jIdentitiesList.${index}.idDocCopy`"
										:required="rules[`jIdentitiesList.${index}.idDocCopy`]?.[0].required">
										<view class="flex flex-row justify-end w-100">
											<fileUpload v-model="item.idDocCopy" @upload="selectUpload" :maxCount="1" />
										</view>
									</u-form-item>
									<u-form-item label="证件反面照片" :prop="`jIdentitiesList.${index}.idDocCopyBack`"
										:required="rules[`jIdentitiesList.${index}.idDocCopyBack`]?.[0].required">
										<view class="flex flex-row justify-end w-100">
											<fileUpload v-model="item.idDocCopyBack" @upload="selectUpload"
												:maxCount="1" />
										</view>
									</u-form-item>
									<u-form-item label="证件有效期开始时间" :prop="`jIdentitiesList.${index}.idDocPeriodBegin`"
										:required="rules[`jIdentitiesList.${index}.idDocPeriodBegin`]?.[0].required">
										<view class="flex flex-row justify-end w-100">
											<view style="width: fit-content;">
												<uni-datetime-picker return-type='string' type="date"
													v-model="item.idDocPeriodBegin" :border="false" :clearIcon='false'
													:end='item.idDocPeriodEnd' />
											</view>
										</view>
									</u-form-item>
									<u-form-item label="证件有效期结束时间" :prop="`jIdentitiesList.${index}.idDocPeriodEnd`"
										:required="rules[`jIdentitiesList.${index}.idDocPeriodEnd`]?.[0].required">
										<view class="flex flex-row justify-end w-100">
											<view style="width: fit-content;">
												<uni-datetime-picker return-type='string' type="date"
													v-model="item.idDocPeriodEnd" :border="false" :clearIcon='false'
													:start='item.idDocPeriodBegin' />
											</view>
										</view>
									</u-form-item>
									<u-form-item label="业务办理授权函"
										:prop="`jIdentitiesList.${index}.businessAuthorizationLetter`"
										:required="rules[`jIdentitiesList.${index}.businessAuthorizationLetter`]?.[0].required">
										<view class="flex flex-row justify-end w-100">
											<fileUpload v-model="item.businessAuthorizationLetter"
												@upload="selectUpload" :maxCount="1" />
										</view>
									</u-form-item>
								</template>
							</template>

							<u-form-item label="联系手机号" prop="jSubject.phone"
								:required="rules['jSubject.phone']?.[0].required">
								<u-input input-align='right' v-model="jSubject.phone" />
							</u-form-item>
							<u-form-item label="联系邮箱" prop="jSubject.email"
								:required="rules['jSubject.email']?.[0].required">
								<u-input input-align='right' v-model="jSubject.email" />
							</u-form-item>
						</view>
					</template>

					<template v-if="current === 1">
						<view class="p-16">
							<group-title>
						<template #icon>
							<view class="main-color">
								<u-icon name="title-icon" custom-prefix="custom-icon" />
							</view>
						</template>
						经营信息</group-title>
						</view>
						<view class="bg-white p-r-16 p-l-16">
							<u-form-item label="主体类型" prop="jSubject.subjectType"
								:required="rules['jSubject.subjectType']?.[0].required">
								<my-select clearable input-align='right' v-model="jSubject.subjectType"
									:options="SUBJECT_TYPE" @change='changesubjectType' />
							</u-form-item>
							<u-form-item label="是否是金融机构" prop="jSubject.financeInstitution"
								:required="rules['jSubject.financeInstitution']?.[0].required">
								<view class="flex flex-row justify-end w-100">
									<uni-data-checkbox v-model="jSubject.financeInstitution" :localdata="YES_OR_NO" />
								</view>
							</u-form-item>
							<template v-if="jSubject.subjectType == 0 || jSubject.subjectType == 1">
								<view class="">
									<u-form-item label="注册号/统一社会信用代码" prop="jSubject.businessLicenseNo"
										:required="rules['jSubject.businessLicenseNo']?.[0].required">
										<u-input input-align='right' v-model="jSubject.businessLicenseNo" />
									</u-form-item>
									<u-form-item label="个体户经营者/法人姓名" prop="jSubject.name"
										:required="rules['jSubject.name']?.[0].required">
										<u-input input-align='right' v-model="jSubject.name" />
									</u-form-item>
									<u-form-item label="注册地址" prop="jSubject.businessLicenseAddress"
										:required="rules['jSubject.businessLicenseAddress']?.[0].required">
										<u-input input-align='right' v-model="jSubject.businessLicenseAddress" />
									</u-form-item>
									<u-form-item label="商户名称" prop="jSubject.businessLicenseName"
										:required="rules['jSubject.businessLicenseName']?.[0].required">
										<u-input input-align='right' v-model="jSubject.businessLicenseName" />
									</u-form-item>
									<u-form-item label="营业执照照片" prop="jSubject.businessLicensePic"
										:required="rules['jSubject.businessLicensePic']?.[0].required">
										<view class="flex flex-row justify-end w-100">
											<fileUpload v-model="jSubject.businessLicensePic" @upload="selectUpload"
												:maxCount="1" />
										</view>
									</u-form-item>
								</view>
							</template>
							<template v-if="jSubject.financeInstitution == 1">
								<view class="">
									<u-form-item label="金融机构类型" prop="jSubject.financeType"
										:required="rules['jSubject.financeType']?.[0].required">
										<my-select clearable input-align='right' v-model="jSubject.financeType"
											:options="FINANCE_TYPE" />
									</u-form-item>
									<u-form-item label="金融机构许可证图片" prop="jSubject.financeLicensePics"
										:required="rules['jSubject.financeLicensePics']?.[0].required">
										<view class="flex flex-row justify-end w-100">
											<fileUpload v-model="jSubject.financeLicensePics" @upload="selectUpload"
												:maxCount="1" />
										</view>
									</u-form-item>
								</view>
							</template>

						</view>
						<view class="p-16">
							<group-title>
						<template #icon>
							<view class="main-color">
								<u-icon name="title-icon" custom-prefix="custom-icon" />
							</view>
						</template>
						经营者/法人信息</group-title>
						</view>
						<view class="bg-white p-r-16 p-l-16">
							<template v-for="(item, index) in jIdentitiesList" :key="`${item?.userType}` - `${index}`">
								<template v-if="item?.userType == 1">
									<view class="">
										<u-form-item label="超级管理员类型" :prop="`jIdentitiesList.${index}.idHolderType`"
											:required="rules[`jIdentitiesList.${index}.idHolderType`]?.[0].required">
											<my-select clearable input-align='right' v-model="item.idHolderType"
												:options="HOLDER_TYPE" />
										</u-form-item>
										<u-form-item label="证件类型" :prop="`jIdentitiesList.${index}.idDocType`"
											:required="rules[`jIdentitiesList.${index}.idDocType`]?.[0].required">
											<my-select clearable input-align='right' v-model="item.idDocType"
												:options="DOC_TYPE" />
										</u-form-item>
										<u-form-item label="证件姓名" :prop="`jIdentitiesList.${index}.idDocName`"
											:required="rules[`jIdentitiesList.${index}.idDocName`]?.[0].required">
											<u-input input-align='right' v-model="item.idDocName" />
										</u-form-item>
										<u-form-item label="法定代表人说明函"
											:prop="`jIdentitiesList.${index}.authorizeLetterCopy`"
											:required="rules[`jIdentitiesList.${index}.authorizeLetterCopy`]?.[0].required">
											<view class="flex flex-row justify-end w-100">
												<fileUpload v-model="item.authorizeLetterCopy" @upload="selectUpload"
													:maxCount="1" />
											</view>
										</u-form-item>
										<u-form-item label="经营者/法人是否为受益人" :prop="`jIdentitiesList.${index}.owner`"
											:required="rules[`jIdentitiesList.${index}.owner`]?.[0].required">
											<view class="flex flex-row justify-end w-100">
												<uni-data-checkbox v-model="item.owner" :localdata="YES_OR_NO" />
											</view>
										</u-form-item>
										<u-form-item label="证件号码" :prop="`jIdentitiesList.${index}.idDocNumber`"
											:required="rules[`jIdentitiesList.${index}.idDocNumber`]?.[0].required">
											<u-input input-align='right' v-model="item.idDocNumber" />
										</u-form-item>
										<u-form-item label="证件居住地址" :prop="`jIdentitiesList.${index}.idDocAddress`"
											:required="rules[`jIdentitiesList.${index}.idDocAddress`]?.[0].required">
											<u-input input-align='right' v-model="item.idDocAddress" />
										</u-form-item>
										<u-form-item label="证件有效期开始时间"
											:prop="`jIdentitiesList.${index}.idDocPeriodBegin`"
											:required="rules[`jIdentitiesList.${index}.idDocPeriodBegin`]?.[0].required">
											<view class="flex flex-row justify-end w-100">
												<view style="width: fit-content;">
													<uni-datetime-picker return-type='string' type="date"
														v-model="item.idDocPeriodBegin" :border="false"
														:clearIcon='false' :end='item.idDocPeriodEnd' />
												</view>
											</view>
										</u-form-item>
										<u-form-item label="证件有效期结束时间" :prop="`jIdentitiesList.${index}.idDocPeriodEnd`"
											:required="rules[`jIdentitiesList.${index}.idDocPeriodEnd`]?.[0].required">
											<view class="flex flex-row justify-end w-100">
												<view style="width: fit-content;">
													<uni-datetime-picker return-type='string' type="date"
														v-model="item.idDocPeriodEnd" :border="false" :clearIcon='false'
														:start='item.idDocPeriodBegin' />
												</view>
											</view>
										</u-form-item>
										<u-form-item label="证件正面照片" :prop="`jIdentitiesList.${index}.idDocCopy`"
											:required="rules[`jIdentitiesList.${index}.idDocCopy`]?.[0].required">
											<view class="flex flex-row justify-end w-100">
												<fileUpload v-model="item.idDocCopy" @upload="selectUpload"
													:maxCount="1" />
											</view>
										</u-form-item>
										<u-form-item label="证件反面照片" :prop="`jIdentitiesList.${index}.idDocCopyBack`"
											:required="rules[`jIdentitiesList.${index}.idDocCopyBack`]?.[0].required">
											<view class="flex flex-row justify-end w-100">
												<fileUpload v-model="item.idDocCopyBack" @upload="selectUpload"
													:maxCount="1" />
											</view>
										</u-form-item>
									</view>
								</template>

							</template>

						</view>
						<view class="p-16">
							<group-title>
						<template #icon>
							<view class="main-color">
								<u-icon name="title-icon" custom-prefix="custom-icon" />
							</view>
						</template>
						最终受益人信息</group-title>
						</view>
						<view class="bg-white p-r-16 p-l-16">
							<view class="p-16">
								<u-button type="primary" @click="addJIdentities">添加最终受益人信息</u-button>
							</view>
							<template v-for="(item, index) in jIdentitiesList" :key="`${item?.userType}` - `${index}`">
								<template v-if="item?.userType == 2">
									<view class="">
										<u-form-item label="证件类型" :prop="`jIdentitiesList.${index}.idDocType`"
											:required="rules[`jIdentitiesList.${index}.idDocType`]?.[0].required">
											<my-select clearable input-align='right' v-model="item.idDocType"
												:options="DOC_TYPE" />
										</u-form-item>
										<u-form-item label="证件姓名" :prop="`jIdentitiesList.${index}.idDocName`"
											:required="rules[`jIdentitiesList.${index}.idDocName`]?.[0].required">
											<u-input input-align='right' v-model="item.idDocName" />
										</u-form-item>
										<u-form-item label="证件号码" :prop="`jIdentitiesList.${index}.idDocNumber`"
											:required="rules[`jIdentitiesList.${index}.idDocNumber`]?.[0].required">
											<u-input input-align='right' v-model="item.idDocNumber" />
										</u-form-item>
										<u-form-item label="证件居住地址" :prop="`jIdentitiesList.${index}.idDocAddress`"
											:required="rules[`jIdentitiesList.${index}.idDocAddress`]?.[0].required">
											<u-input input-align='right' v-model="item.idDocAddress" />
										</u-form-item>
										<u-form-item label="证件有效期开始时间"
											:prop="`jIdentitiesList.${index}.idDocPeriodBegin`"
											:required="rules[`jIdentitiesList.${index}.idDocPeriodBegin`]?.[0].required">
											<view class="flex flex-row justify-end w-100">
												<view style="width: fit-content;">
													<uni-datetime-picker return-type='string' type="date"
														v-model="item.idDocPeriodBegin" :border="false"
														:clearIcon='false' :end='item.idDocPeriodEnd' />
												</view>
											</view>
										</u-form-item>
										<u-form-item label="证件有效期结束时间" :prop="`jIdentitiesList.${index}.idDocPeriodEnd`"
											:required="rules[`jIdentitiesList.${index}.idDocPeriodEnd`]?.[0].required">
											<view class="flex flex-row justify-end w-100">
												<view style="width: fit-content;">
													<uni-datetime-picker return-type='string' type="date"
														v-model="item.idDocPeriodEnd" :border="false" :clearIcon='false'
														:start='item.idDocPeriodBegin' />
												</view>
											</view>
										</u-form-item>
										<u-form-item label="证件正面照片" :prop="`jIdentitiesList.${index}.idDocCopy`"
											:required="rules[`jIdentitiesList.${index}.idDocCopy`]?.[0].required">
											<view class="flex flex-row justify-end w-100">
												<fileUpload v-model="item.idDocCopy" @upload="selectUpload"
													:maxCount="1" />
											</view>
										</u-form-item>
										<u-form-item label="证件反面照片" :prop="`jIdentitiesList.${index}.idDocCopyBack`"
											:required="rules[`jIdentitiesList.${index}.idDocCopyBack`]?.[0].required">
											<view class="flex flex-row justify-end w-100">
												<fileUpload v-model="item.idDocCopyBack" @upload="selectUpload"
													:maxCount="1" />
											</view>
										</u-form-item>
										<view class="p-16">
											<u-button type="primary" @click="delJIdentities(index)">删减最终受益人信息</u-button>
										</view>
									</view>
								</template>
							</template>
						</view>
					</template>

					<template v-if="current === 2">
						<view class="">
							<view class="p-16">
								<group-title>
						<template #icon>
							<view class="main-color">
								<u-icon name="title-icon" custom-prefix="custom-icon" />
							</view>
						</template>
						其他信息</group-title>
							</view>
							<view class="bg-white p-r-16 p-l-16">
								<u-form-item label="商户简称" prop="jSubject.merchantShortName"
									:required="rules['jSubject.merchantShortName']?.[0].required">
									<u-input input-align='right' v-model="jSubject.merchantShortName" />
								</u-form-item>
								<u-form-item label="服务电话" prop="jSubject.servicePhone"
									:required="rules['jSubject.servicePhone']?.[0].required">
									<u-input input-align='right' v-model="jSubject.servicePhone" />
								</u-form-item>
							</view>
							<view class="p-16">
								<group-title>
						<template #icon>
							<view class="main-color">
								<u-icon name="title-icon" custom-prefix="custom-icon" />
							</view>
						</template>
						场景</group-title>
							</view>
							<view class="bg-white p-r-16 p-l-16">
								<u-form-item label="交易场景" prop="sceneTypeArr"
									:required="rules['sceneTypeArr']?.[0].required">
									<view class="flex flex-row justify-end w-100">
										<uni-data-checkbox multiple v-model="formData.sceneTypeArr"
											:localdata="scenesOptions" @change="handleSceneTypeArr" />
									</view>
								</u-form-item>

								<template v-for="(item, index) in jSceneList" :key="item?.sceneType">
									<view class="p-y-16">
										<group-title>
						<template #icon>
							<view class="main-color">
								<u-icon name="title-icon" custom-prefix="custom-icon" />
							</view>
						</template>
						{{`${selectDictLabel(SCENES_TYPE_WECHAT, item?.sceneType)}场景`}}</group-title>
									</view>
									<!-- 线下 -->
									<template v-if="item?.sceneType == 0">
										<view>
											<u-form-item label="门店名称" :prop="`jSceneList.${index}.name`"
												:required="rules[`jSceneList.${index}.name`]?.[0].required">
												<u-input input-align='right' v-model="item.name" />
											</u-form-item>
											<u-form-item label="线下场所省市编码" :prop="`jSceneList.${index}.shopAddress1`"
												:required="rules[`jSceneList.${index}.shopAddress1`]?.[0].required">
												<myArea input-align='right' clearable v-model="item.shopAddress1"
													@change="(val) => changeArea(val, item)" :getMultiple="true" />
											</u-form-item>
											<u-form-item label="线下场所地址" :prop="`jSceneList.${index}.url`"
												:required="rules[`jSceneList.${index}.url`]?.[0].required">
												<u-input input-align='right' v-model="item.url" />
											</u-form-item>
											<u-form-item label="线下场所对应的商家AppID" :prop="`jSceneList.${index}.appid`"
												:required="rules[`jSceneList.${index}.appid`]?.[0].required">
												<u-input input-align='right' v-model="item.appid" />
											</u-form-item>
											<u-form-item label="店铺内景图片" :prop="`jSceneList.${index}.productUrl`"
												:required="rules[`jSceneList.${index}.productUrl`]?.[0].required">
												<view class="flex flex-row justify-end w-100">
													<fileUpload v-model="item.productUrl" @upload="selectUpload"
														:maxCount="1" />
												</view>
											</u-form-item>
											<u-form-item label="店铺门头照图片" :prop="`jSceneList.${index}.indexUrl`"
												:required="rules[`jSceneList.${index}.indexUrl`]?.[0].required">
												<view class="flex flex-row justify-end w-100">
													<fileUpload v-model="item.indexUrl" @upload="selectUpload"
														:maxCount="1" />
												</view>
											</u-form-item>
										</view>
									</template>
									<!-- 服务号与公众号场景 -->
									<template v-if="item?.sceneType == 1">
										<view>
											<u-form-item label="appId类型" :prop="`jSceneList.${index}.appidType`"
												:required="rules[`jSceneList.${index}.appidType`]?.[0].required">
												<my-select clearable input-align='right' v-model="item.appidType"
													:options="APPID_TYPE" />
											</u-form-item>
											<u-form-item label="商家服务号或公众号AppID" :prop="`jSceneList.${index}.appid`"
												:required="rules[`jSceneList.${index}.appid`]?.[0].required">
												<u-input input-align='right' v-model="item.appid" />
											</u-form-item>
											<u-form-item label="服务号或公众号页面截图" :prop="`jSceneList.${index}.indexUrl`"
												:required="rules[`jSceneList.${index}.indexUrl`]?.[0].required">
												<view class="flex flex-row justify-end w-100">
													<fileUpload v-model="item.indexUrl" @upload="selectUpload"
														:maxCount="5" />
												</view>
											</u-form-item>
										</view>
									</template>
									<!-- 小程序 -->
									<template v-if="item?.sceneType == 2">
										<view>
											<u-form-item label="appId类型" :prop="`jSceneList.${index}.appidType`"
												:required="rules[`jSceneList.${index}.appidType`]?.[0].required">
												<my-select clearable input-align='right' v-model="item.appidType"
													:options="APPID_TYPE" />
											</u-form-item>
											<u-form-item label="商家小程序AppID" :prop="`jSceneList.${index}.appid`"
												:required="rules[`jSceneList.${index}.appid`]?.[0].required">
												<u-input input-align='right' v-model="item.appid" />
											</u-form-item>
											<u-form-item label="小程序截图" :prop="`jSceneList.${index}.indexUrl`"
												:required="rules[`jSceneList.${index}.indexUrl`]?.[0].required">
												<view class="flex flex-row justify-end w-100">
													<fileUpload v-model="item.indexUrl" @upload="selectUpload"
														:maxCount="5" />
												</view>
											</u-form-item>
										</view>
									</template>
									<!-- pc -->
									<template v-if="item?.sceneType == 3">
										<view>
											<u-form-item label="互联网网站域名" :prop="`jSceneList.${index}.name`"
												:required="rules[`jSceneList.${index}.name`]?.[0].required">
												<u-input input-align='right' v-model="item.name" />
											</u-form-item>
											<u-form-item label="互联网网站对应的商家AppID" :prop="`jSceneList.${index}.appid`"
												:required="rules[`jSceneList.${index}.appid`]?.[0].required">
												<u-input input-align='right' v-model="item.appid" />
											</u-form-item>
											<u-form-item label="接入网址授权函" :prop="`jSceneList.${index}.authorizationUrl`"
												:required="rules[`jSceneList.${index}.authorizationUrl`]?.[0].required">
												<view class="flex flex-row justify-end w-100">
													<fileUpload v-model="item.authorizationUrl" @upload="selectUpload"
														:maxCount="1" />
												</view>
											</u-form-item>
										</view>
									</template>
									<!-- app -->
									<template v-if="item?.sceneType == 4">
										<view>
											<u-form-item label="appId类型" :prop="`jSceneList.${index}.appidType`"
												:required="rules[`jSceneList.${index}.appidType`]?.[0].required">
												<my-select clearable input-align='right' v-model="item.appidType"
													:options="APPID_TYPE" />
											</u-form-item>
											<u-form-item label="商家应用AppID" :prop="`jSceneList.${index}.appid`"
												:required="rules[`jSceneList.${index}.appid`]?.[0].required">
												<u-input input-align='right' v-model="item.appid" />
											</u-form-item>
											<u-form-item label="App截图" :prop="`jSceneList.${index}.indexUrl`"
												:required="rules[`jSceneList.${index}.indexUrl`]?.[0].required">
												<view class="flex flex-row justify-end w-100">
													<fileUpload v-model="item.indexUrl" @upload="selectUpload"
														:maxCount="4" />
												</view>
											</u-form-item>
										</view>
									</template>
									<!-- 企业微信场景 -->
									<template v-if="item?.sceneType == 5">
										<view>
											<u-form-item label="商家企业微信CorpID" :prop="`jSceneList.${index}appid`"
												:required="rules[`jSceneList.${index}.appid`]?.[0].required">
												<u-input input-align='right' v-model="item.appid" />
											</u-form-item>
											<u-form-item label="企业微信页面截图" :prop="`jSceneList.${index}.payUrl`"
												:required="rules[`jSceneList.${index}.payUrl`]?.[0].required">
												<view class="flex flex-row justify-end w-100">
													<fileUpload v-model="item.payUrl" @upload="selectUpload"
														:maxCount="5" />
												</view>
											</u-form-item>
										</view>
									</template>
								</template>
							</view>
						</view>
					</template>

					<template v-if="current === 3">
						<view class="">
							<view class="p-16">
								<group-title>
						<template #icon>
							<view class="main-color">
								<u-icon name="title-icon" custom-prefix="custom-icon" />
							</view>
						</template>
						结算银行账户信息</group-title>
							</view>
							<view class="bg-white p-r-16 p-l-16">
								<u-form-item label="账户类型" prop="jBankAccounts.bankAccountType"
									:required="rules['jBankAccounts.bankAccountType']?.[0].required">
									<my-select clearable input-align='right' v-model="jBankAccounts.bankAccountType"
										:options="REGIST_BANK_ACCOUNT_TYPE" @change='changeBankAccountType' />
								</u-form-item>
								<u-form-item label="开户名称" prop="jBankAccounts.accountName"
									:required="rules['jBankAccounts.accountName']?.[0].required">
									<u-input input-align='right' v-model="jBankAccounts.accountName" />
								</u-form-item>
								<u-form-item label="开户银行" prop="jBankAccounts.accountBank"
									:required="rules['jBankAccounts.accountBank']?.[0].required">
									<my-select clearable input-align='right' v-model="jBankAccounts.accountBank"
										:queryParams="{ channelId: rowData.channelId }"
										:api="jBankAccounts.bankAccountType == '0' ?businessApi.getCorporateBanking:businessApi.getPersonalBanking"
										queryParamKey="nameLike" labelKey='accountBank' valueKey='accountBank'
										@change='changeAccountBank' />
								</u-form-item>
								<u-form-item label="结算信息省份" prop="jBankAccounts.settleProvinceName"
									:required="rules['jBankAccounts.settleProvinceName']?.[0].required">
									<my-select clearable input-align='right' v-model="jBankAccounts.settleProvinceName"
										:queryParams="{ channelId: rowData.channelId }" :api="registApi.getProvinces"
										queryParamKey="nameLike" valueKey='name' @change='changeProvince' />
								</u-form-item>
								<u-form-item label="结算信息城市" prop="jBankAccounts.settleCityName"
									:required="rules['jBankAccounts.settleCityName']?.[0].required">
									<my-select clearable input-align='right' v-model="jBankAccounts.settleCityName"
										:queryParams="{channelId:rowData.channelId,provinceCode: jBankAccounts.settleProvinceCode ?? '0'}"
										:api="registApi.getCitys" queryParamKey="nameLike" valueKey='name'
										@change='changeCity' />
								</u-form-item>
								<u-form-item label="开户银行全称（含支行）" prop="jBankAccounts.bankName"
									:required="rules['jBankAccounts.bankName']?.[0].required">
									<my-select clearable input-align='right' v-model="jBankAccounts.bankName"
										:queryParams="{channelId: rowData.channelId,cityCode: jBankAccounts.settleCityCode ?? -1,bankAliasCode: jBankAccounts.bankAliasCode ?? -1,}"
										:api="registApi.getBranches" queryParamKey="nameLike" valueKey='bankBranchName'
										labelKey='bankBranchName' @change='changeBankName' @focus="focusBankName" />
								</u-form-item>
								<u-form-item label="开户银行银行号" prop="jBankAccounts.bankBranchId"
									:required="rules['jBankAccounts.bankBranchId']?.[0].required">
									<u-input input-align='right' v-model="jBankAccounts.bankBranchId" />
								</u-form-item>
								<u-form-item label="银行账号" prop="jBankAccounts.accountNumber"
									:required="rules['jBankAccounts.accountNumber']?.[0].required">
									<u-input input-align='right' v-model="jBankAccounts.accountNumber" />
								</u-form-item>

							</view>
							<view class="p-16">
								<group-title>
						<template #icon>
							<view class="main-color">
								<u-icon name="title-icon" custom-prefix="custom-icon" />
							</view>
						</template>
						结算规则</group-title>
							</view>
							<view class="bg-white p-r-16 p-l-16">
								<u-form-item label="一级经营类目" prop="jSubject.mccCodeOne"
									:required="rules['jSubject.mccCodeOne']?.[0].required">
									<my-select clearable input-align='right' v-model="jSubject.mccCodeOne"
										:queryParams="headParams" :initParams="headInitParams" :api="businessApi.page"
										labelKey='categoryName' valueKey='categoryCode' @change='changeMccCodeOne' />
								</u-form-item>
								<u-form-item label="二级经营类目" prop="jSubject.mccCodeTwo"
									:required="rules['jSubject.mccCodeTwo']?.[0].required">
									<my-select clearable input-align='right' v-model="jSubject.mccCodeTwo"
										:queryParams="qualificationParams" :initParams="qualificationInitParams"
										:api="businessApi.page" labelKey='categoryName' valueKey='categoryCode'
										@change='changeMccCodeTwo' />
								</u-form-item>
								<u-form-item label="企业特殊资质图片" prop="jSubject.specialQualifications"
									:required="rules['jSubject.specialQualifications']?.[0].required">
									<view class="flex flex-row justify-end w-100">
										<fileUpload v-model="jSubject.specialQualifications" @upload="selectUpload"
											:maxCount="1" />
									</view>
								</u-form-item>
							</view>
						</view>
					</template>

					<template v-if="current === 4">
						<view class="">
							<view class="p-16">
								<group-title>
						<template #icon>
							<view class="main-color">
								<u-icon name="title-icon" custom-prefix="custom-icon" />
							</view>
						</template>
						补充材料</group-title>
							</view>
							<view class="bg-white p-r-16 p-l-16">
								<u-form-item label="法人开户承诺函" prop="jSubject.legalPersonCommitment"
									:required="rules['jSubject.legalPersonCommitment']?.[0].required">
									<view class="flex flex-row justify-end w-100">
										<fileUpload v-model="jSubject.legalPersonCommitment" @upload="selectUpload"
											:maxCount="1" />
									</view>
								</u-form-item>
								<u-form-item label="法人开户意愿视频" prop="jSubject.legalPersonVideo"
									:required="rules['jSubject.legalPersonVideo']?.[0].required">
									<view class="flex flex-row justify-end w-100">
										<fileUpload v-model="jSubject.legalPersonVideo" @upload="selectUpload"
											:maxCount="1" accept="video" showType="video" />
									</view>
								</u-form-item>
								<u-form-item label="补充材料" prop="jSubject.businessAdditionPics"
									:required="rules['jSubject.businessAdditionPics']?.[0].required">
									<view class="flex flex-row justify-end w-100">
										<fileUpload v-model="jSubject.businessAdditionPics" @upload="selectUpload"
											:maxCount="1" />
									</view>
								</u-form-item>
								<u-form-item label="费率" prop="jSubject.businessAdditionMsg"
									:required="rules['jSubject.businessAdditionMsg']?.[0].required">
									<u-input input-align='right' v-model="jSubject.businessAdditionMsg" maxlength='512'
										type='textarea ' />
								</u-form-item>
							</view>
						</view>
					</template>
				</view>
				<!-- <view class="">
					<view class="p-16 flex flex-row justify-between" v-if="formType=='view'">
						<view class="w-100">
							<u-button @click="updateForm">修改</u-button>
						</view>
					</view>
					<view class="p-16 flex flex-row justify-between" v-else>
						<view class="w-30">
							<u-button @click="getHistoryData">调取进件资料</u-button>
						</view>
						<view class="w-30">
							<u-button @click="handleSave">保存</u-button>
						</view>
						<view class="w-30">
							<u-button type="primary" @click="submit">提交</u-button>
						</view>
					</view>
				</view> -->
			</u-form>
			<view class="formBtn"
				v-if="(userType == 2 && rowData.status == '0' && rowData.checkStatus == '-1' )||formType == 'add'">
				<view class="p-16 flex flex-row justify-between" v-if="formType=='view'">
					<view class="w-30">
						<u-button @click="updateForm">修改</u-button>
					</view>
					<view class="w-30">
						<u-button @click="previousStep" :disabled="current == 0">上一步</u-button>
					</view>
					<view class="w-30">
						<u-button @click="nextStep" :disabled="current == stepsItems.length - 1">下一步</u-button>
					</view>
				</view>
				<view class="p-16 flex flex-row justify-between" v-else>
					<view class="w-24">
						<u-button @click="getHistoryData">调取进件</u-button>
					</view>
					<view class="w-24">
						<u-button @click="handleSave">保存</u-button>
					</view>
					<view class="w-24" v-if="current == 0">
						<u-button @click="previousStep">上一步</u-button>
					</view>
					<view class="w-24" v-if="current !== stepsItems.length - 1">
						<u-button @click="nextStep">下一步</u-button>
					</view>
					<view class="w-24" v-if="current === stepsItems.length - 1">
						<u-button type="primary" @click="submit">提交</u-button>
					</view>
				</view>
			</view>
			<view class="formBtn" v-else>
				<view class="p-16 flex flex-row justify-between">
					<view class="w-49">
						<u-button @click="previousStep" :disabled="current == 0">上一步</u-button>
					</view>
					<view class="w-49">
						<u-button @click="nextStep" v-if="current !== stepsItems.length - 1">下一步</u-button>
					</view>
				</view>
			</view>
		</view>
	</main-content>
</template>
<script setup name='index'>
	import {
		reactive,
		ref,
		getCurrentInstance,
		computed,
		nextTick,
		toRefs,
		watch
	} from 'vue'
	import {
		onLoad,
		onShow,
		onReady
	} from '@dcloudio/uni-app'
	import {
		useCommonStore
	} from '@/stores/common.js'
	import {
		useUserStore
	} from '@/stores/user.js'
	import {
		SUBJECT_TYPE, // 主体类型
		SCENES_TYPE_WECHAT, //场景类型
		SERVICE_TYPE, //服务类型
		AUDIT_STATUS, //审核状态
		REGIST_BANK_ACCOUNT_TYPE, //银行账户类型
		HOLDER_TYPE, // 证件持有人类型
		DOC_TYPE, // 证件类型
		YES_OR_NO, // 是否
		FINANCE_TYPE, // 金融机构类型
		APPID_TYPE, // appid类型
	} from '@/common/dict.js'
	import {
		debounce,
		selectDictLabel,
		parseTime,
		cloneDeep,
		parseQueryParams,
		modifyFields,
		strToArr
	} from '@/common/common.js'
	import {
		myUpload
	} from '@/pages-menus/common/myUpload.js'
	import {
		registApi
	} from '@/pages-menus/common/api/regist/index.js'
	import {
		businessApi
	} from '@/pages-menus/common/api/regist/business.js'

	import myArea from '@/components/my-area/index.vue'
	import fileUpload from '@/pages-menus/components/file-upload/index.vue'
	import {
		validatePhoneNot,
		isNum
	} from '@/common/validate'
	const userType = computed(() => {
		return useUserStore().userType
	})
	const commonStore = useCommonStore()
	const {
		proxy
	} = getCurrentInstance()

	const formType = ref('add')
	const rowData = ref({})

	const maiColor = computed(() => {
		return proxy.$System.maiColor.value
	})

	// 表单步骤
	const current = ref(0)
	const stepsItems = ref([{
			title: '超级管理员信息',
		},
		{
			title: '主体资料',
		},
		{
			title: '经营资料',
		},
		{
			title: '结算信息',
		},
		{
			title: '补充材料',
		},
	])
	// 下一步
	const nextStep = async () => {
		if (formType.value == 'view') {
			current.value >= stepsItems.value.length - 1 ? (current.value = stepsItems.value.length - 1) :
				current
				.value++
		} else {
			formDataRef.value.validate((valid) => {
				if (!valid) return
				current.value >= stepsItems.value.length - 1 ? (current.value = stepsItems.value.length -
						1) :
					current
					.value++
			})
		}
	}
	// 上一步
	const previousStep = () => {
		current.value <= 0 ? (current.value = 0) : current.value--
	}
	// 表单步骤

	const formDataRef = ref(null)

	const validatorFn = (rule, value, callback) => {
		const judge = rule.judge ?? (() => {
			return true
		})
		const mes = rule.message || '不能为空'

		if (judge(value)) {
			callback(new Error(mes));
		} else {
			callback();
		}
	}

	const rules = computed(() => {
		let obj = {
			sceneTypeArr: [{
				required: false,
				validator: validatorFn,
				judge: (val) => {
					return !val || val.length === 0
				},
				message: '交易场景 不能为空!',

			}], //交易场景
			'jSubject.account': [{
				required: true,
				message: '商户号/支付宝账号不能为空!'
			}],
			'jSubject.name': [{
				required: true,
				message: '姓名不能为空!'
			}],
			'jSubject.phone': [{
					required: true,
					message: '手机号码不能为空!'
				},
				{
					validator: validatePhoneNot,
				},
			],
			'jSubject.email': [{
				required: true,
				message: '联系邮箱不能为空!'
			}],
			'jSubject.mccCode': [{
				required: true,
				message: '经营类目 不能为空!',

			}],
			'jSubject.mccCodeOne': [{
				required: true,
				message: '经营类目 不能为空!',

			}],
			'jSubject.mccCodeTwo': [{
				required: true,
				message: '经营类目 不能为空!',

			}],
			'jSubject.specialQualifications': [{
				required: false,
				validator: validatorFn,
				judge: (val) => {
					return jSubject.value.specialLicenseType == '1' && (!val || val.length ===
						0)
				},
			}],
			'jSubject.businessLicenseNo': [{
				required: true,
				message: '营业执照号码 不能为空!',

			}],
			'jSubject.longTerm': [{
				required: true,
				message: '营业期限是否长期有效 不能为空!',

			}],
			'jSubject.businessLicenseName': [{
				required: true,
				message: '商户名称 不能为空!',

			}],
			'jSubject.financeType': [{
				required: true,
				message: '金融机构类型 不能为空!',

			}],
			'jSubject.merchantShortName': [{
				required: true,
				message: '商户简称 不能为空!',

			}],
			'jSubject.subjectType': [{
				required: true,
				message: '主体类型 不能为空!',
			}],
			'jSubject.servicePhone': [{
				required: true,
				message: '服务电话 不能为空!',

			}],
			'jSubject.businessLicensePic': [{
				required: true,
				message: '营业执照照片 不能为空!',

			}],

			'jBankAccounts.bankAccountType': [{
				required: true,
				message: '账户类型 不能为空!'
			}],
			'jBankAccounts.accountName': [{
				required: true,
				message: '开户名称 不能为空!',

			}],
			'jBankAccounts.accountBank': [{
				required: true,
				message: '开户银行 不能为空!',

			}],
			'jBankAccounts.bankAddressCode': [{
				required: false,
				message: '开户行地区 不能为空!',

			}],
			'jBankAccounts.bankBranchId': [{
				required: false,
				message: '开户银行银行号 不能为空!',

			}],
			'jBankAccounts.settleProvinceCode': [{
				required: false,
				validator: validatorFn,
				judge: (val) => {
					return jBankAccounts.value.needBankBranch && (!val || val.length === 0)
				},
				message: '结算信息省份 不能为空!',

			}],
			'jBankAccounts.settleCityCode': [{
				required: false,
				validator: validatorFn,
				judge: (val) => {
					return jBankAccounts.value.needBankBranch && (!val || val.length === 0)
				},
				message: '结算信息城市 不能为空!',

			}],
			'jBankAccounts.settleProvinceName': [{
				required: false,
				validator: validatorFn,
				judge: (val) => {
					return jBankAccounts.value.needBankBranch && (!val || val.length === 0)
				},
				message: '结算信息省份 不能为空!',

			}],
			'jBankAccounts.settleCityName': [{
				required: false,
				validator: validatorFn,
				judge: (val) => {
					return jBankAccounts.value.needBankBranch && (!val || val.length === 0)
				},
				message: '结算信息城市 不能为空!',

			}],
			'jBankAccounts.bankName': [{
				required: false,
				validator: validatorFn,
				judge: (val) => {
					return jBankAccounts.value.needBankBranch && (!val || val.length === 0)
				},
				message: '开户银行全称（含支行） 不能为空!',

			}],
			'jBankAccounts.accountNumber': [{
				required: true,
				message: '银行账号 不能为空!',

			}, {
				validator: isNum
			}],
		}

		if (jSceneList.value && jSceneList.value.length > 0) {
			jSceneList.value.forEach((item, index) => {
				obj[`jSceneList.${index}.appMarket`] = [{
					required: true,
					message: '投放应用市场 不能为空!',

				}] //投放应用市场 0苹果 1应用宝 2华为 3 360 4小米 5豌豆夹 6其他
				obj[`jSceneList.${index}.merchantShortName`] = [{
					required: true,
					message: '商户简称 不能为空!',

				}] //商户简称
				obj[`jSceneList.${index}.servicePhone`] = [{
					required: true,
					message: '客服电话 不能为空!',

				}] //客服电话
				obj[`jSceneList.${index}.indexUrl`] = [{
					required: true,
					message: '小程序/h5网站/应用首页/门店门头/服务或公众号页面 不能为空!',

				}] //首页 小程序/h5网站/应用首页/门店门头/服务或公众号页面
				obj[`jSceneList.${index}.payUrl`] = [{
					required: true,
					message: 'h5网站/应用支付页/网站支付页/企微页面 不能为空!',

				}] //支付 h5网站/应用支付页/网站支付页/企微页面
				obj[`jSceneList.${index}.demoAccount`] = [{
					required: true,
					message: '测试用户 不能为空!',

				}] //测试用户
				obj[`jSceneList.${index}.appStatus`] = [{
					required: true,
					message: '应用状态 不能为空!',

				}] //应用状态 0未上线 1已上线
				obj[`jSceneList.${index}.url`] = [{
					required: true,
					message: '网站地址/门店详细地址/应用下载链接 不能为空!',

				}] //网站地址/门店详细地址/应用下载链接
				obj[`jSceneList.${index}.sId`] = [{
					required: true,
					message: '商户经营信息表编号 不能为空!',

				}] //商户经营信息表编号
				obj[`jSceneList.${index}.authorizationUrl`] = [{
					required: true,
					message: '授权 不能为空!',

				}] //授权 h5网站授权/app授权/接入网址授权
				obj[`jSceneList.${index}.merchantId`] = [{
					required: true,
					message: '商户编号 不能为空!',

				}] //商户编号
				obj[`jSceneList.${index}.productUrlM`] = [{
					required: true,
					message: '图片 不能为空!',

				}] //商品 商品服务/网站商品页/店铺内景
				obj[`jSceneList.${index}.appid`] = [{
					required: true,
					message: 'appID 不能为空!',

				}] //商户appID/企微corpId
				obj[`jSceneList.${index}.name`] = [{
					required: true,
					message: '名称 不能为空!',

				}] //小程序名称/应用名称/门店名称/网站名称
				obj[`jSceneList.${index}.demoPass`] = [{
					required: true,
					message: '测试密码 不能为空!',

				}] //测试密码
				obj[`jSceneList.${index}.appidType`] = [{
					required: true,
					message: 'appid类型 不能为空!',
				}] //appid类型
				obj[`jSceneList.${index}.shopProvinceCode`] = [{
					required: true,
					message: ' 不能为空!',

				}] //省份
				obj[`jSceneList.${index}.shopCityCode`] = [{
					required: true,
					message: ' 不能为空!',

				}] //市
				obj[`jSceneList.${index}.shopDistrictCode`] = [{
					required: true,
					message: ' 不能为空!',

				}] //区县
				obj[`jSceneList.${index}.shopAddress1`] = [{
					required: true,
					message: '地址 不能为空!',

				}] //地址
				obj[`jSceneList.${index}.remarkUrl`] = [{
					required: true,
					message: '备注 不能为空!',

				}] //备注
				obj[`jSceneList.${index}.id`] = [{
					required: true,
					message: '编号 不能为空!',

				}] //编号
				obj[`jSceneList.${index}.productUrl`] = [{
					required: true,
					message: '商品 不能为空!',

				}] //商品 商品服务/网站商品页
			})
		}
		if (jIdentitiesList.value && jIdentitiesList.value.length > 0) {
			jIdentitiesList.value.forEach((item, index) => {
				obj[`jIdentitiesList.${index}.idHolderType`] = [{
					required: true,
					message: '证件持有人类型 不能为空!',

				}]
				obj[`jIdentitiesList.${index}.idDocType`] = [{
					required: false,
					validator: validatorFn,
					judge: (val) => {
						return ((item.userType == '0' && item
								.idHolderType == 'SUPER') ||
							(item.userType == '1' && item
								.idHolderType == 'LEGAL') ||
							item.userType == '2') && (!val || val.length === 0)
					},
					message: '证件类型 不能为空!',
				}, ]
				obj[`jIdentitiesList.${index}.idDocName`] = [{
					required: true,
					message: '证件姓名 不能为空!',

				}]
				obj[`jIdentitiesList.${index}.idDocNumber`] = [{
					required: false,
					validator: validatorFn,
					judge: (val) => {
						return ((item.userType == '0' && item
								.idHolderType == 'SUPER') || item
							.userType != '0') && (!val || val.length === 0)
					},
					message: '证件号码 不能为空!',
				}]
				obj[`jIdentitiesList.${index}.idDocAddress`] = [{
					required: false,
					validator: validatorFn,
					judge: (val) => {
						return ((item.userType == '1' && jSubject
								.value.subjectType == '1') || item
							.userType != '1') && (!val || val.length === 0)
					},
					message: '证件居住地址 不能为空!',
				}, ]
				obj[`jIdentitiesList.${index}.idDocPeriodBegin`] = [{
					required: false,
					validator: validatorFn,
					judge: (val) => {
						return ((item.userType == '0' && item
								.idHolderType == 'SUPER') || item
							.userType != '0') && (!val || val.length === 0)
					},
					message: '证件有效期开始时间 不能为空!',
				}, ]
				obj[`jIdentitiesList.${index}.idDocPeriodEnd`] = [{
					required: false,
					validator: validatorFn,
					judge: (val) => {
						return ((item.userType == '0' && item
								.idHolderType == 'SUPER') || item
							.userType != '0') && (!val || val.length === 0)
					},
					message: '证件有效期结束时间 不能为空!',
				}, ]
				obj[`jIdentitiesList.${index}.idDocLongTermFlag`] = [{
					required: true,
					message: '证件是否长期有效 不能为空!',
				}]
				obj[`jIdentitiesList.${index}.userType`] = [{
					required: true,
					message: '用户类型 不能为空!',

				}]
				obj[`jIdentitiesList.${index}.owner`] = [{
					required: false,
					validator: validatorFn,
					judge: (val) => {
						return (item.userType == '1' && jSubject
							.value.subjectType == '1') && (!val || val.length === 0)
					},
					message: '是否受益人 不能为空!',

				}]
				obj[`jIdentitiesList.${index}.businessAuthorizationLetter`] = [{
					required: false,
					validator: validatorFn,
					judge: (val) => {
						return (item.idHolderType == 'SUPER') && (!val || val.length === 0)
					},
					message: '业务办理授权函 不能为空!',

				}]
				obj[`jIdentitiesList.${index}.authorizeLetterCopy`] = [{
					required: false,
					validator: validatorFn,
					judge: (val) => {
						return (item.idHolderType == 'SUPER') && (!val || val.length === 0)
					},
					message: '法定代表人说明函 不能为空!',

				}]
				obj[`jIdentitiesList.${index}.idDocCopy`] = [{
					required: false,
					validator: validatorFn,
					judge: (val) => {
						return ((item.userType == '0' && item
								.idHolderType == 'SUPER') || item
							.userType != '0') && (!val || val.length === 0)
					},
					message: '证件正面照片 不能为空!',
				}]
				obj[`jIdentitiesList.${index}.idDocCopyBack`] = [{
					required: false,
					validator: validatorFn,
					judge: (val) => {
						return ((item.userType == '0' && item
								.idHolderType == 'SUPER') || item
							.userType != '0') && (!val || val.length === 0)
					},
					message: '证件反面照片 不能为空!',
				}]
			})
		}
		return obj
	})

	// 图片字段
	const imgField = [
		'specialQualifications',
		'qualifications',
		'businessLicensePic',
		'financeLicensePics',
		'businessLicenseAuthPic',
		'indexUrl',
		'remarkUrl',
		'payUrl',
		'authorizationUrl',
		'productUrl',
		'idDocCopy',
		'idDocCopyBack',
		'authorizeLetterCopy',
		'businessAuthorizationLetter',
		'legalPersonCommitment',
		'legalPersonVideo',
		'businessAdditionPics',
	]
	// 场景子表字段
	const jSceneListChild = {
		appMarket: undefined, //投放应用市场 0苹果 1应用宝 2华为 3 360 4小米 5豌豆夹 6其他
		merchantShortName: undefined, //商户简称
		servicePhone: undefined, //客服电话
		demoAccount: undefined, //测试用户
		type: undefined, //平台类型 0支付宝 1微信
		appidType: undefined, //appid类型
		appStatus: undefined, //应用状态 0未上线 1已上线
		url: undefined, //网站地址/门店详细地址/应用下载链接
		sId: undefined, //商户经营信息表编号
		merchantId: undefined, //商户编号
		sceneType: undefined, //场景类型 0线下 1服务号和公众号 2小程序 3pc 4app 5企业微信 6移动h5
		appid: undefined, //商户appID/企微corpId
		name: undefined, //小程序名称/应用名称/门店名称/网站名称
		shopCityCode: undefined, //市
		demoPass: undefined, //测试密码
		shopDistrictCode: undefined, //区县
		id: undefined, //编号
		shopProvinceCode: undefined, //省份
		indexUrl: [], //首页 小程序/h5网站/应用首页/门店门头/服务或公众号页面
		remarkUrl: [], //备注
		payUrl: [], //支付 h5网站/应用支付页/网站支付页/企微页面
		authorizationUrl: [], //授权 h5网站授权/app授权/接入网址授权
		productUrl: [], //商品 商品服务/网站商品页
	}
	// 商户身份信息子表字段
	const jIdentitiesListChild = {
		idHolderType: undefined, //证件持有人类型（LEGAL：经营者/法人；SUPER：经办人）
		idDocType: undefined, //证件类型: 0: 中国大陆居民-身份证 1: 其他国家或地区居民-护照 2: 中国香港居民-来往内地通行证 3: 中国澳门居民-来往内地通行证 4: 中国台湾居民-来往大陆通行证 5: 外国人居留证 6: 港澳居民证 7: 台湾居民证
		idDocName: undefined, //证件姓名
		idDocNumber: undefined, //证件号码
		idDocAddress: undefined, //证件居住地址
		idDocPeriodBegin: undefined, //证件有效期开始时间
		idDocPeriodEnd: undefined, //证件有效期结束时间
		idDocLongTermFlag: undefined, //证件是否长期有效
		userType: undefined, //用户类型 0超级管理员 1经营者/法人 2最终受益人
		owner: undefined, //是否受益人 0否1是
		businessAuthorizationLetter: [], //业务办理授权函（仅当 contact_type= SUPER 时填写）
		authorizeLetterCopy: [], //法定代表人说明函
		idDocCopy: [], //证件正面照片
		idDocCopyBack: [], //证件反面照片
	}
	const initData = {
		mpdId: undefined, //商户进件关联编号
		jBankAccounts: {
			channelId: undefined, //通道id
			bankAccountType: undefined, //银行账户类型 0: 对公银行账户 1: 经营者个人银行卡
			accountName: undefined, //账户名称
			accountBank: undefined, //开户银行
			bankAddressCode: undefined, //银行地址编码
			bankBranchId: undefined, //银行支行ID
			bankName: undefined, //银行名称
			accountNumber: undefined, //银行账号
			needBankBranch: undefined, //是否需要支行
			clearingBankCode: undefined, //结算账户清算⾏号
			settleProvinceCode: undefined, //结算信息省份代码
			settleProvinceName: undefined, //结算信息省份名称
			settleCityCode: undefined, //结算信息城市代码
			settleCityName: undefined, //结算信息城市名称
			serviceType: undefined, //服务类型：1代收；2代付；3自动分账；4不分账
			auditStatus: undefined, //审核状态：1待审核；2审核中；3审核通过；4审核拒绝
			auditMsg: undefined, //审核原因
			settlementType: undefined, //结算方式：1银行卡；2支付宝账号
			outCode: undefined, //外部编号
			utime: undefined, //可选
		}, //结算银行账户表
		jSubject: {
			financeInstitution: undefined, //是否为金融机构 0否1是
			businessLicenseMobile: undefined, //营业执照法人手机号
			merchantShortName: undefined, //商户简称
			dateLimitation: undefined, //营业期限
			settlementId: undefined, //结算规则ID
			subjectType: undefined, //主体类型： 0: 营业执照上的主体类型一般为个体户、个体工商户、个体经营 1: 营业执照上的主体类型一般为有限公司、有限责任公司 2: 包括各级、各类政府机关，如机关党委、税务、民政、人社、工商、商务、市监等 3:包括国内各级、各类政府机构、事业单位等。 如：公安、党团、司法、交通、旅游、工商税务、市政、医疗、教育、学校等机构 4: 包括社会团体、民办非企业、基金会、基层群众性自治组织、农村集体经济组织等组织
			mccCode: undefined, //经营类目
			mccCodeOne: undefined, //经营类目
			mccCodeTwo: undefined, //经营类目
			activitiesAdditions: undefined, //活动附加说明 用,拼接
			qualificationType: undefined, //所属行业类型
			qualifications: undefined, //特殊资质说明 用,拼接
			signAndAuth: undefined, //签约且授权标识，默认为false，只进行签约操作； 如果设置为true，则表示签约成功后，会自动进行应用授权操作。
			longTerm: 1, //营业执照是否长期有效 0否 1是
			activitiesId: undefined, //活动ID
			merchantId: undefined, //自定义商户编号
			rate: undefined, //服务费率（%），0.38~0.6 之间（小数点后两位，可取0.38%及0.6%）。 当签约且授权标识 sign_and_auth=true 时，该费率信息必填
			activitiesRate: undefined, //活动费率
			id: undefined, //编号
			debitActivitiesRate: undefined, //借记卡活动费率
			creditActivitiesRate: undefined, //信用卡活动费率
			email: undefined, //邮箱
			specialLicenseType: undefined, //特殊资质类型
			certificateLetterCopy: undefined, //单位证明函照片
			businessLicenseAddress: undefined, //营业执照的注册地址，若该字段未填写，系统将会查询国家工商信息填入。需注意若工商信息查询不到，则会被审核驳回。
			servicePhone: undefined, //服务电话
			businessAdditionMsg: undefined, //补充说明
			businessLicenseName: undefined, //营业执照商户名称
			businessLicenseNo: undefined, //营业执照号码
			phone: undefined, //手机号
			name: undefined, //姓名
			financeType: undefined, //金融机构类型 为金融机构时必传
			storeInfo: undefined, //销售场景
			account: undefined, //支付宝账号
			specialQualifications: [], //企业特殊资质图片
			businessLicensePic: [], //营业执照图片
			financeLicensePics: [], //金融机构许可证图片 用,拼接
			businessLicenseAuthPic: [], //营业执照授权函
			legalPersonCommitment: [], //法人开户承诺函1、请上传法定代表人或负责人亲笔签署的开户承诺函扫描件（下载模板）。亲笔签名承诺函内容清晰可见，不得有涂污，破损，字迹不清晰现象； 2、请填写通过图片上传API预先上传图片生成好的MediaID
			legalPersonVideo: [], //法人开户意愿视频 1、建议法人按如下话术录制“法人开户意愿视频”： 我是#公司全称#的法定代表人（或负责人），特此证明本公司申请的商户号为我司真实意愿开立且用于XX业务（或XX服务）。我司现有业务符合法律法规及腾讯的相关规定。 2、支持上传20M内的视频，格式可为avi、wmv、mpeg、mp4、mov、mkv、flv、f4v、m4v、rmvb； 3、请填写通过视频上传API预先上传视频生成好的MediaID 。
			businessAdditionPics: [], //补充材料 1、最多可上传5张照片； 2、请填写通过图片上传API预先上传图片生成好的MediaID。
		}, //商户经营信息表出参
		apiType: 1, //接口类型 0通用 1当面付
		jIdentitiesList: [], //商户身份信息
		jSceneList: [], //商户场景信息
		sceneTypeArr: [], //场景类型
	}
	const formData = reactive(cloneDeep(initData))
	const {
		jBankAccounts,
		jIdentitiesList,
		jSubject,
		jSceneList,
		sceneTypeArr
	} = toRefs(formData)

	//保存
	const handleSave = async () => {
		const param = {
			...cloneDeep(formData),
		}
		imgInit(param)
		if (formType.value != 'view') {
			try {
				let res = await registApi.save(param)
				uni.showToast({
					title: `保存成功！`,
					icon: 'success',
					duration: 2000
				});
				return res
			} catch (error) {
				console.error(error)
			}
		}
	}
	// 提交
	const submit = async () => {
		formDataRef.value.validate((valid) => {
			if (valid) {
				handleSave().then(() => {
					const param = {
						checkStatus: 0,
						id: rowData.value.id
					}
					registApi.submit(param).then(() => {
						uni.showToast({
							title: `提交成功！`,
							icon: 'success',
							duration: 2000
						});
						proxy.$System.goTo('/pages-menus/pages/regist/index')
						resetForm()
					})
				})
			}
		})
	}

	//调用进件资料
	function getHistoryData() {
		let p = {
			id: rowData.value.id,
			channelType: rowData.value.channelType
		}
		registApi
			.findIdByChannelType(p)
			.then((res) => {
				if (proxy.$System.isEmpty(res?.data)) return
				let resData = res.data
				imgInit(resData)
				mergeArea(resData)
				Object.assign(formData, resData)
				getSceneTypeArr()
				initFormList()
			})
	}

	const resetForm = () => {
		// 重置表单的 UI 状态
		try {
			formDataRef.value.resetFields()
		} catch (error) {
			console.error(error)
		}
		// 重置表单数据
		Object.assign(formData, cloneDeep(initData))
	}

	const getForm = (data) => {
		let p = {
			mpdId: data.id,
			type: data.channelType
		}
		registApi.findId(p).then((res) => {
			if (res.code != 200) return
			let resData = res.data
			resData.mpdId = data.id
			imgInit(resData)
			mergeArea(resData)
			Object.assign(formData, resData)
			getSceneTypeArr()
			initFormList()
		}).catch((err) => {
			console.error(err)
			initFormList()
		})
	}
	const titleMap = {
		add: '新增微信资料',
		update: '修改微信资料',
		view: '查看微信资料',
	}

	const updateForm = () => {
		formType.value = 'update'
		// 动态设置标题
		uni.setNavigationBarTitle({
			title: titleMap[formType.value]
		})
	}

	// 选择商户===》
	const changeMch = (val) => {
		console.log('选择商户===>', val);
		// if (!val[0]) {
		// 	formData.value.merchantId = undefined
		// 	return
		// }
		// formData.value.merchantId = data[0].id
	}

	const limitUpload = {
		comment: {
			fileType: ['.jpg', '.jpeg', '.png', '.bmp', '.gif'],
			fileSize: 2,
		},
		legalPersonVideo: {
			fileType: ['.avi', '.wmv', '.mpeg', '.mp4', '.mov', '.mkv', '.flv', '.f4v', '.m4v', '.rmvb'],
			fileSize: 5,
		},
	}

	const beforeUpload = (file, fileList, type) => {
		let limitUploadKeys = Object.keys(limitUpload)
		type = limitUploadKeys.includes(type) ? type : 'comment'
		// 校检文件类型
		if (limitUpload[type].fileType.length) {
			const fileExt = file.name.substring(file.name.lastIndexOf('.')).toLowerCase()
			const isTypeOk = limitUpload[type].fileType.includes(fileExt)
			if (!isTypeOk) {
				uni.showToast({
					title: `文件格式不正确, 请上传${limitUpload[type].fileType.toString().replace(/\./g, '').replace(/,/g, '、')}格式文件!`,
					icon: 'error',
					duration: 2000
				});
				return false
			}
		}

		// 校检文件大小
		if (limitUpload[type].fileSize) {
			const isLt = file.size / 1024 / 1024 < limitUpload[type].fileSize
			if (!isLt) {
				uni.showToast({
					title: `上传文件大小不能超过 ${limitUpload[type].fileSize} MB!`,
					icon: 'error',
					duration: 2000
				});
				return false
			}
		}

		return true
	}

	// 上传文件自定义的方法
	const uploadFunc = async (file, fieldName) => {
		// 确保获取到文件对象
		const fileObj = file
		if (!fileObj) {
			return
		}
		const response = await myUpload(file)
		console.log('response==>', response)
	}
	const selectUpload = async (e) => {
		console.log('选择文件：', e)
		if (e.length > 0) {
			e.forEach(async fileItem => {
				if (beforeUpload(fileItem)) {
					let res = await uploadFunc(fileItem)
				}
			})
		}

	}

	let areaFieldArr = ['shopProvinceCode', 'shopCityCode', 'shopDistrictCode']
	// 地址拆分
	const changeArea = (val, data) => {
		if (Array.isArray(val) && val.length > 0) {
			val.forEach((item, index) => {
				data[areaFieldArr[index]] = item
			})
		} else {
			areaFieldArr.forEach(item => {
				data[item] = ''
			})
		}
	}
	// 地址合并
	function mergeArea(data) {
		data.jSceneList.forEach((item) => {
			if (item.sceneType == '0') {
				for (let i = 0; i <= areaFieldArr.length; i++) {
					if (!item[areaFieldArr[i]]) {
						item.shopAddress1 = item[areaFieldArr[i - 1]]
					}
				}
			}
		})
	}
	// 图片初始化
	function imgInit(resData) {
		modifyFields(resData, imgField, (value, key) => {
			let val
			if (proxy.$System.isEmpty(value)) return
			if (typeof value === 'string') {
				val = strToArr(value).map((item, index) => {
					return {
						uid: `db-file-${index}`,
						name: `${key}${index > 0 ? '_' + index : ''}`,
						status: 'done',
						extname: 'text',
						url: item,
					}
				})
			}
			if (Array.isArray(value)) {
				val = value.map((e) => {
					let url = ''
					if (e?.res?.url || e?.res?.data?.url) {
						url = e.res.url || e.res.data.url
					} else {
						url = e.url
					}
					return url
				}).toString()
			}
			return val
		})
	}

	// 获取场景列表--场景初始化
	function getSceneTypeArr() {
		if (!proxy.$System.isEmpty(jSceneList.value) && jSceneList.value.length > 0) {
			sceneTypeArr.value = [...new Set(jSceneList.value.map((item) => item.sceneType))]
		} else {
			sceneTypeArr.value = []
		}
	}
	// 获取场景类型
	const handleSceneTypeArr = (val) => {
		sceneChange()
	}
	const sceneChange = () => {
		let sceneArr = jSceneList.value.map((item) => item?.sceneType)
		// formData.jSceneList.push({ ...cloneDeep(jSceneListChild), sceneType: 0 })
		formData.sceneTypeArr.forEach((item) => {
			if (!sceneArr.includes(item)) {
				formData.jSceneList.push({
					...cloneDeep(jSceneListChild),
					sceneType: item,
					type: rowData.value?.channelType
				})
			}
		})
		sceneArr.forEach((item, index) => {
			if (!formData.sceneTypeArr.includes(item)) {
				jSceneList.value.splice(index, 1)
			}
		})
	}

	/* 经营类目 */
	// 主体类型
	const headParams = computed(() => {
		return {
			pCategoryCode: '000000',
			applicableMerchants: jSubject.value.subjectType,
		}
	})
	const headInitParams = computed(() => {
		return {
			categoryCode: jSubject.value.mccCodeOne,
		}
	})
	const qualificationParams = computed(() => {
		return {
			pCategoryCode: jSubject.value.mccCodeOne ? jSubject.value.mccCodeOne : 'unknown',
		}
	})
	const qualificationInitParams = computed(() => {
		return {
			categoryCode: jSubject.value.mccCodeTwo,
		}
	})
	// 主体类目
	const changesubjectType = (val) => {}
	// 切换行业一级类目
	const changeMccCodeOne = (val) => {
		console.log('一级类目==》', val);
		jSubject.value.mccCodeTwo = undefined
	}
	// 切换行业二级类目
	const changeMccCodeTwo = (val) => {
		console.log('二级类目==>', val)
		// 赋值费率
		jSubject.value.rate = val[0].rate
		// 获取规则id
		jSubject.value.settlementId = val[0].mccCode
		// 是否上传特殊资质
		jSubject.value.specialLicenseType = val[0].qualificationsType
	}

	/* 经营类目 */

	// 改变账户类型
	const changeBankAccountType = () => {
		jBankAccounts.value.accountBank = undefined
		jBankAccounts.value.bankBranchId = undefined
	}
	// 改变开户银行(针对直连银行)
	const changeAccountBank = (val, opt) => {
		console.log('开户银行===>', opt)
		jBankAccounts.value.bankAliasCode = opt[0].bankAliasCode
		jBankAccounts.value.needBankBranch = opt[0].needBankBranch
		jBankAccounts.value.bankName = undefined
		// jBankAccounts.value.bankAddressCode = opt.map((e) => e.code).toString()
	}
	// 改变省份城市
	const changeProvince = (val, opt) => {
		jBankAccounts.value.settleProvinceCode = opt[0].code
		jBankAccounts.value.settleCityCode = undefined
		jBankAccounts.value.settleCityName = undefined
	}
	const changeCity = (val, opt) => {
		jBankAccounts.value.settleCityCode = opt[0].code
	}
	// 改变支行 开户银行全称（含支行）
	const changeBankName = (val, opt) => {
		// jBankAccounts.value.accountNumber = opt.map((e) => e.accountBankCode).toString()
		jBankAccounts.value.bankBranchId = opt[0].bankBranchId
	}
	const focusBankName = () => {
		if (!isEmpty(jBankAccounts.value.bankAliasCode)) return
		uni.showToast({
			title: `请先选择开户银行`,
			icon: 'error',
			duration: 2000
		});
		jBankAccounts.value.accountBank = undefined
	}

	/* 添加受益人、删除受益人 商户身份信息 */
	const addJIdentities = () => {
		let userType2 = formData.jIdentitiesList.reduce((count, item) => count + (item.userType === 2 ? 1 : 0), 0)
		if (userType2 < 4) {
			formData.jIdentitiesList.push({
				...cloneDeep(jIdentitiesListChild),
				userType: 2
			})
		} else {
			uni.showToast({
				title: `最多添加4个受益人`,
				icon: 'error',
				duration: 2000
			});
		}
	}
	const delJIdentities = (index) => {
		formData.jIdentitiesList.splice(index, 1)
	}
	/* 添加受益人、删除受益人 商户身份信息 */

	/* 必填场景 */
	const requiredScene = computed(() => {
		return []
	})
	const scenesOptions = computed(() => {
		return SCENES_TYPE_WECHAT.map((item) => {
			return {
				...item,
				disabled: requiredScene.value.includes(item.value),
				label: item.label,
				text: item.label,
				value: item.value,
			}
		})
	})

	/* 数组表单初始化 */
	function initFormList() {
		// 必填人员处理
		formData.mpdId = formData?.mpdId || rowData.value?.id
		// 确保 jIdentitiesList 存在且是数组
		if (!Array.isArray(formData.jIdentitiesList)) {
			formData.jIdentitiesList = []
		}
		const requiredUserTypes = [0, 1]
		// 一次性检查所需 userType 是否都存在
		const existingTypes = new Set(formData.jIdentitiesList.map((item) => item.userType))
		requiredUserTypes.forEach((userType) => {
			if (!existingTypes.has(userType)) {
				formData.jIdentitiesList.push({
					...cloneDeep(jIdentitiesListChild),
					userType
				})
			}
		})
	}

	watch([() => rowData.value, () => formType.value], () => {
		formData.apiType = rowData.value.apiType
		if (rowData.value?.apiType) {
			formData.apiType = rowData.value.apiType
		}
		// if (rowData.value?.id) {
		// 	formData.mpdId = rowData.value?.id
		// }
		if ((formType.value == 'update' || formType.value == 'view')) {
			getForm(cloneDeep(rowData.value))
		}
		if (formType.value == 'add') {
			initFormList()
		}
	}, {
		deep: true,
		immediate: true
	})
	watch(() => rules.value, () => {
		nextTick(() => {
			formDataRef.value?.setRules(rules.value);
		})
	}, {
		deep: true,
		immediate: true
	})

	onLoad(async (opt) => {
		let options = parseQueryParams(opt)
		formType.value = options.formType ?? 'add'
		if (!proxy.$System.isEmpty(options.rowData)) {
			rowData.value = options.rowData
		}
		// 动态设置标题
		uni.setNavigationBarTitle({
			title: titleMap[formType.value]
		})
	})
	onReady(() => {
		nextTick(() => {
			formDataRef.value?.setRules(rules.value);
		})
		// paging.value.reload()
	})
</script>
<style lang='scss' scoped>
	.view-group {
		background-color: #fff;
	}

	.isDisabled {
		position: relative;
	}

	.isDisabled:before {
		position: absolute;
		content: '';
		display: block;
		width: 100%;
		height: 100%;
		background-color: rgba(25, 25, 25, .05);
		z-index: 9;
	}

	.formBtn {
		position: fixed;
		bottom: 0;
		width: 100%;
		z-index: 9;
		background-color: #fff;
		box-shadow: 0 -3px 6px #e1e1e1;
	}

	.operate-box {
		position: fixed;
		z-index: 99;
		bottom: 50rpx;
	}

	.tar {
		:deep(.u-input) {
			text-align: right !important;
		}
	}
</style>